#ifndef __UPDATE_IMAGE_DECODE_H__
#define __UPDATE_IMAGE_DECODE_H__
#include <stdint.h>

struct data_frame {
	uint32_t addr;
	uint16_t len;
	uint16_t index;
	struct data_frame *last;
	struct data_frame *next;
	uint16_t buf_len;
	uint8_t *buf;
};

extern struct data_frame *df_list;
extern void df_list_free(void);
extern int load_image(uint8_t *path);
extern int df_list_remove_first(void);
extern void dump_buf(const uint8_t *buf, int ret, const uint8_t *tag);

#define df_list_for_each(pos, head) \
	for (pos = head->next; pos != (head); pos = pos->next)

#define df_list_for_each_safe(pos, n, head) \
	for (pos = head->next, n = pos->next; \
		pos != (head); pos = n, n = pos->next)

/* Size and offset in record string */
#define RECORED_TYPE_SIZE	2
#define RECORED_LEN_SIZE	2
#define RECORED_HEAD_SIZE	(RECORED_TYPE_SIZE + RECORED_LEN_SIZE)
#define RECORED_ADDR_SIZE	8
#define RECORED_CS_SIZE		2

#define RECORED_TYPE_OFFSET	0
#define RECORED_LEN_OFFSET	(RECORED_TYPE_OFFSET + RECORED_TYPE_SIZE)
#define RECORED_ADDR_OFFSET	(RECORED_LEN_OFFSET + RECORED_LEN_SIZE)
#define RECORED_DATA_OFFSET	(RECORED_ADDR_OFFSET + RECORED_ADDR_SIZE)

/* Length in bytes */
#define RECORED_ADDR_BYTES		(RECORED_ADDR_SIZE >> 1)
#define RECORED_LEN_BYTES		RECORED_LEN_SIZE
#define RECORED_CS_BYTES		(RECORED_CS_SIZE >> 1)
#define GET_DATA_BYTES(sline_len)	(sline_len - RECORED_ADDR_BYTES -\
						RECORED_CS_BYTES)
#define GET_SLINE_BYTES(rec_size)	((rec_size - RECORED_HEAD_SIZE) >> 1)
#define DATA_FRAME_MAX_LEN		(1024 - 6 - 11)

#endif /* __UPDATE_IMAGE_DECODE_H__ */
